package com.sumainfor.pc.epc.service.impl;

import com.sumainfor.common.Constants;
import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.CustomMap;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ComUtils;
import com.sumainfor.common.utlis.HtmlUtil;
import com.sumainfor.common.utlis.ParamsCommon;
import com.sumainfor.pc.epc.dao.HoHousingAlterInfoMapper;
import com.sumainfor.pc.epc.dao.HoHousingAlterMapper;
import com.sumainfor.pc.epc.dao.HoHousingPlanMapper;
import com.sumainfor.pc.epc.dao.UtilsMapper;
import com.sumainfor.pc.epc.feign.Zfeign.ZzuulFeign;
import com.sumainfor.pc.epc.service.HoHousingAlterInfoService;
import com.sumainfor.pc.epc.service.HoHousingAlterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.awt.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 房源配置变更
 */
@Service
public class HoHousingAlterInfoServiceImpl implements HoHousingAlterInfoService {

    private ReentrantLock lock = new ReentrantLock(false);
    Logger log = LoggerFactory.getLogger(HoHousingAlterInfoServiceImpl.class);
    @Autowired
    private HoHousingAlterInfoMapper hoHousingAlterInfoMapper;

    /**
     * 新增房源配置详表
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public JsonResult updateHoHai(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        /**
         * 加锁操作
         */
        lock.lock();
        try {
            try {
                if ( params.get("HouConIds")==null || params.get("HouConId")==null
                        || params.get("Identifier")==null || params.get("Intelligent")==null) {
                    return result.putFailed("参数不正确");
                }

                params.put("by", ContextUtils.getUserId());//操作人
                params.put("term", "3");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
                params.put("fnc",
                        this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                ParamsCommon.commonUpdateParms(params);
                Integer count=hoHousingAlterInfoMapper.updateHoHai(params);
                if (count!=null && count==1){
                    result.putSuccess("操作成功");
                }else{
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    result.putFailed("服务器繁忙");
                }
            } catch (Exception e) {
                result.putFailed("服务器繁忙");
                e.printStackTrace();
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
        } finally {
            lock.unlock();
        }

        return result;
    }
}
